﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Runtime;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using NLog;

namespace EpubFactory.Hetushu
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        static Logger logger = LogManager.GetLogger("app",typeof(App));
        protected override void OnStartup(StartupEventArgs e)
        {
            //Current.Dispatcher.UnhandledException += Dispatcher_UnhandledException;
            //AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            base.OnStartup(e);
        }

        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            logger.Error("非UI异常", e.ExceptionObject as Exception);
            //e.IsTerminating = false;
        }

        private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            logger.Error("UI异常", e.Exception);
            //e.Handled = true;
        }

        protected override void OnActivated(EventArgs e)
        {
            int renderingTier = (RenderCapability.Tier >> 16);
            string text = null;
            switch (renderingTier)
            {
                case 0:
                    text = string.Format("{0} No hardware acceleration.", renderingTier.ToString());
                    break;
                case 1:
                    text = string.Format("{0} Partial hardware acceleration.", renderingTier.ToString());
                    break;
                case 2:
                    text = string.Format("{0} Total hardware acceleration.", renderingTier.ToString());
                    break;
            }
            logger.Debug(text);

            base.OnActivated(e);
            //Mapper.Initialize(cfg =>
            //{
            //    cfg.AddProfile<HetushuProfile>();
            //});

        }
    }
    //public class HetushuProfile : Profile
    //{
    //    public HetushuProfile()
    //    {

    //    }
    //}
}
